<?php

$smarty->configLoad($lang . '/options.module.php');
$language = parse_ini_file($lang . '/breadcrumb.module.php', true);
$breadcrumb = $language['options'];
$langu = parse_ini_file($lang . '/options.module.php', true);

$contents = file_get_contents("http://178.63.72.14/inzane/current.txt");
if(empty($_GET['backup'])) {
	$_GET['backup'] = '';
}
if ($_GET['backup'] == 'cms') {
	$db = new DBBackup(array( 
		'driver' => 'mysql', 
		'host' => DB_HOST, 
		'user' => DB_USER, 
		'password' => DB_PASS, 
		'database' => DB_CMS 
	)); 
	$backup = $db->backup(); 
	if(!$backup['error']){ 
		$time = date('d.m.Y', time());
		if(!file_exists('_backup/backup_'.$time)) {
			mkdir('_backup/backup_'.$time);
		}
		$handle = fopen('_backup/backup_'.$time.'/hybridcms_backup_'.$time.'.sql','w+');
		fwrite($handle,$backup['msg']);
		fclose($handle);
	}
} elseif ($_GET['backup'] == 'game') {
	set_time_limit(0);
	@ini_set("memory_limit",'1024M');
	$main->jqmodal('backup');
		$db = new DBBackup(array( 
			'driver' => 'mysql', 
			'host' => DB_HOST, 
			'user' => DB_USER, 
			'password' => DB_PASS, 
			'database' => DB_GAME 
		)); 
		$backup = $db->backup(); 
		if(!$backup['error']){ 
			$time = date('d.m.Y', time());
			if(!file_exists('_backup/backup_'.$time)) {
				mkdir('_backup/backup_'.$time);
			}
			$handle = fopen('_backup/backup_'.$time.'/gameserver_backup_'.$time.'.sql','w+');
			fwrite($handle,$backup['msg']);
			fclose($handle);
		}
} elseif ($_GET['backup'] == 'login') {
	$main->jqmodal('backup');
	$db = new DBBackup(array( 
			'driver' => 'mysql', 
			'host' => DB_HOST, 
			'user' => DB_USER, 
			'password' => DB_PASS, 
			'database' => DB_LOGIN 
		)); 
		$backup = $db->backup(); 
		if(!$backup['error']){ 
			$time = date('d.m.Y', time());
			if(!file_exists('_backup/backup_'.$time)) {
				mkdir('_backup/backup_'.$time);
			}
			$handle = fopen('_backup/backup_'.$time.'/loginserver_backup_'.$time.'.sql','w+');
			fwrite($handle,$backup['msg']);
			fclose($handle);
		}
}
if ($version === $contents) {
	$checked = $langu['noupdate'];
	$version = $langu['currentversion'] . ' ' . $version;
} else {
	$checked = $langu['foundupdate'];
	$version = '<a href="index.php?mod=options&page=update"><input type="button" class="alt_btn" value="' . $langu['updatenow'] . '"></a>';
}
$smarty->assign('checked', $checked);
$smarty->assign('version', $version);
$sql = 'SELECT * FROM ' . DB_CMS . '.website_settings';
$dbh = $connection->query($sql);
$row = $dbh->fetch(PDO::FETCH_ASSOC);
$smarty->assign('title', $row['title']);
$smarty->assign('ip_server', $row['ip_server']);
$smarty->assign('port_loginserver', $row['loginserver_port']);
$smarty->assign('port_gameserver', $row['gameserver_port']);
$smarty->assign('ip_teamspeak', $row['ip_teamspeak']);
$smarty->assign('port_teamspeak', $row['teamspeak_port']);
if (isset($_POST['submit'])) {
	$main->logAction($_SESSION['id'], 'settings');
	$sql = 'UPDATE ' . DB_CMS . '.website_settings SET ip_server = :ip_server, gameserver_port = :gameserver_port, loginserver_port = :loginserver_port, ip_teamspeak = :ip_teamspeak, teamspeak_port = :teamspeak_port';
	$dbh = $connection->prepare($sql);
	$dbh->bindValue(':ip_server', $_POST['ip_server']);
	$dbh->bindValue(':gameserver_port', $_POST['game']);
	$dbh->bindValue(':loginserver_port', $_POST['login']);
	$dbh->bindValue(':ip_teamspeak', $_POST['teamspeak']);
	$dbh->bindValue(':teamspeak_port', $_POST['teamspeak_port']);
	$dbh->execute();
	$main->jqmodal('edited');
	echo '<meta http-equiv="refresh" content="5; URL=index.php?mod=options">';
}
$template = 'options/index.tpl';
?>
 